'''
陈超依 19377189
现代程序设计第八次作业
'''

import random  #模拟耗内存操作
from line_profiler import LineProfiler
from memory_profiler import profile
from tqdm.std import trange
import os
import playsound

N = 1000

def check_path(func):
    def wrapper(*args,**kwargs):
        if not os.path.exists(args[0].path):
            print("指定的路径不存在，正在创建路径\n")
            os.makedirs(args[0].path)
            print("路径创建完成\n")
        else:
            print("指定的路径存在\n")
        return func(*args,**kwargs) 
    return wrapper

class test():
    def __init__(self, path : str):
        self.path = path
        self.data = []
    @check_path
    #@profile
    def create(self):
        for i in trange(N):
            self.data.append([])
            for j in range(N):
                self.data[i].append(random.random())
    def save(self):
        f = open(self.path + '\\test.txt', mode='w')
        for i in self.data:
            for j in i:
                f.write(str(j))
                f.write('\t')
            f.write('\n')

def test_line_profiler(demo : test):
    p = LineProfiler()
    p.wrap_function = p(demo.create)
    p.wrap_function()
    p.print_stats()

def play_sound(func):
    def wrapper(*args,**kwargs):
        playsound.playsound('E:/QQmusic/demo.mp3')
        return func(*args,**kwargs) 
    return wrapper

@play_sound
def main():
    demo = test('E:\\Py_Programs\\week20')
    #test_line_profiler(demo)
    demo.create()

if __name__=='__main__':
	main()
